package com.demo.pojo;

import lombok.Data;

/**
 * 统一返回前端的数据
 * @param <T>
 */
@Data
public class ResultVO<T> {
    private Integer code; //编码：1成功，0为失败
    private String msg; //错误信息
    private T data; //数据

    public static ResultVO success() {
        ResultVO resultVO = new ResultVO();
        resultVO.code = 1;
        resultVO.msg = "success";
        return resultVO;
    }

    public static <T> ResultVO<T> success(T object) {
        ResultVO<T> resultVO = new ResultVO();
        resultVO.data = object;
        resultVO.code = 1;
        resultVO.msg = "success";
        return resultVO;
    }

    public static ResultVO error(String msg) {
        ResultVO resultVO = new ResultVO();
        resultVO.msg = msg;
        resultVO.code = 0;
        return resultVO;
    }
}
